import { createStore } from 'vuex'
import { getCart } from '../service/cart.js'
import { getLocal } from '../common/js/ustil.js'

export default createStore({
  state: {
    countCart: 0,
    isLoge:false
  },
  mutations: {
    loginStatus(state) {
      const token = getLocal('token')
      if (token) {
        state.isLogin = true
      }
    },
    addCart(state, payload) {
      state.cartCount = payload.count
    }
  },
  actions: {
   // 获取购物车列表数据
   async updateCart(ctx) {
    const { data } = await getCart()
    // console.log(ctx.count);
    ctx.commit('addCart', {
      count: data.length || 0
    })
  }
  },
  modules: {
  }
})
